
package com.shine.core
{
	/**
	 *  A ClassFactory instance is a "factory object" which Flex uses
	 *  to generate instances of another class, each with identical properties.
	 */
	public class ClassFactory implements IFactory
	{
		/**
	     *  The Class that the <code>newInstance()</code> method uses
		 *  to generate objects from this factory object.
	     */
	    public var generator:Class;
	    /**
		 *	An Object whose name/value pairs specify the properties to be set
		 *  on each object generated by the <code>newInstance()</code> method.
		 */
		public var properties:Object = null;
		/**
	     *  Constructor.
	     *
	     *  @param generator The Class that the <code>newInstance()</code> method uses
		 *  to generate objects from this factory object.
	     */
	    public function ClassFactory(generator:Class = null,properties:Object = null)
	    {
			super();
	
	    	this.generator = generator;
	    	this.properties = properties;
	    }
	    
		/**
		 *  Creates a new instance of the <code>generator</code> class,
		 *  with the properties specified by <code>properties</code>.
		 *
		 *  <p>This method implements the <code>newInstance()</code> method
		 *  of the IFactory interface.</p>
		 *
		 *  @return The new instance that was created.
		 */
		public function newInstance():*
		{
			var instance:Object = new generator();
	        if (properties != null)
	        {
	        	for (var p:String in properties)
				{
	        		instance[p] = properties[p];
				}
	       	}
	       	return instance;
		}
	}
}